perf(web): skip base64 for oversized image candidates - #5220
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved 2a67bcf This is a straightforward performance optimization that adds early-exit logic to avoid expensive base64 encoding when the output would clearly exceed the budget. The caller already handles null returns correctly, and user-facing behavior is unchanged. You can customize Macroscope's approvability policy. Learn more. |
What Changed
Why
Image compression previously converted every canvas candidate to base64 before checking whether it fit. Large images repeated this work across each quality and downscale attempt.
In CI, the existing 12-test image compression suite dropped from 28.99 seconds and a timeout to 5.48 seconds. A focused local run completed in 1.19 seconds.
Checklist
Model: GPT-5.6; harness: T3 Code.
Note
Low Risk
Localized performance change in client-side image encoding; no auth or persistence contract changes beyond failing when no candidate fits instead of returning an over-budget data URL from one encode pass.
Overview
Image compression in
imageCompression.tsavoids expensive base64 work when an encoded candidate is already over the character budget.encodeToDataUrlbecomesencodeCanvaswith abudgetCharsargument. On the HTML canvas path it only keepstoDataURLoutput whendataUrl.length <= budgetChars. On OffscreenCanvas, it estimates data URL length from the blob size and skipsblobToDataUrlwhen that estimate exceeds the budget, returning{ dataUrl: null, mimeType }instead.encodeWithinBudgetno longer tracks the smallest over-budget encoding across quality steps. It returns the first encoding that fits, ornullif every attempt in that pass is too large—so callers rely on smaller fallback scale passes inreencodeWithinBudgetrather than accepting a single pass that still overflows the budget.Reviewed by Cursor Bugbot for commit f91ad4f. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Skip base64 encoding for oversized image candidates in
encodeWithinBudgetencodeCanvasin imageCompression.ts now accepts abudgetCharsparameter and returnsnullfordataUrlwhen the encoded size exceeds the budget, avoiding unnecessary base64 conversion for large blobs.encodeWithinBudgetnow returnsnullwhen no encoding fits within the budget, rather than falling back to the smallest over-budget encoding.nullwhen no candidate fits.Macroscope summarized f91ad4f.